//
//  AddressMangeVC.m
//  BigJoy
//
//  Created by Rowling on 2017/7/10.
//  Copyright © 2017年 Rowling. All rights reserved.
//

#import "AddressMangeVC.h"
#import "upDownButton.h"
#import <ContactsUI/ContactsUI.h>
#import "CitySelectView.h"

@interface AddressMangeVC ()<CNContactPickerDelegate>
@property (weak, nonatomic) IBOutlet upDownButton *chosePeopleButton;
@property (weak, nonatomic) IBOutlet UITextField *nameText;
@property (weak, nonatomic) IBOutlet UITextField *phoneText;
@property (weak, nonatomic) IBOutlet UITextField *addressText;
@property (weak, nonatomic) IBOutlet UITextField *detailAdText;
@property (weak, nonatomic) IBOutlet UITextField *mailNumText;

@end

@implementation AddressMangeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.chosePeopleButton.unReadCount = 0;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
// 选择联系人
- (IBAction)chosePeopleButtonClick:(id)sender {
    CNContactPickerViewController * contactVc = [CNContactPickerViewController new];
    contactVc.delegate = self;
    [self presentViewController:contactVc animated:YES completion:^{
    }];
}

//选择完成代理回调
-(void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact{
    NSLog(@"name:%@%@",contact.familyName,contact.givenName);
    CNLabeledValue * labValue = [contact.phoneNumbers lastObject];
    NSLog(@"phone:%@",[labValue.value stringValue]);
    self.phoneText.text = [labValue.value stringValue];
    self.nameText.text = [NSString stringWithFormat:@"%@%@",contact.familyName,contact.givenName];
}
//取消选择回调
- (void)contactPickerDidCancel:(CNContactPickerViewController *)picker{
    [picker dismissViewControllerAnimated:YES completion:nil];
}
// 默认按钮
- (IBAction)defaultButtonClick:(UIButton *)sender {
    sender.selected = !sender.selected;
}

// 地址选择
- (IBAction)addressChose:(id)sender {
    CitySelectView * cityView = [CitySelectView fastLogin];
    XMweakSelf;
    [cityView setAdBlock:^(NSString * str){
        NSLog(@"%@",str);
        weakSelf.addressText.text = str;
    }];
    cityView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    [XMKEYWINDOWXM addSubview:cityView];
}

@end
